Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
php "like" button and .post method

I am implementing a very simple solution for "love it" button. I created a database, an index.php and a survey.js. On the Database site everything is working, the mysqli strings are all fine. When the button is clicked the js increase the value +1 to show on index.php.

Problem is that the $_POST['loveit'] to updated the database is not passing and the database at the end is not updated. Here is the index.php:

<html>
<body>
  <?php
  if ($_POST['loveit']) {
    mysqli_query($con,"UPDATE survey2 SET loveit=loveit+1 WHERE id=1");
  }
  ?>

  <div class="grid">
    <span id="status"></span><br>
    <input type="button" value="<?php echo $loveit; ?>" class="button_loveit" id="loveitBtn" />
  </div>

  <script type="text/javascript" src="../js/jquery.min.js"></script>
  <script type="text/javascript" src="../js/survey.js"></script>
</body>
</html>

and here the survey.js:

$(document).ready(function() {
  $("#loveitBtn").removeAttr("disabled");
  $('#loveitBtn').click(function(e) {
    var val = parseInt($('#loveitBtn').val(), 10);
    $.post("../survey/index.php", {op: "loveitBtn"}, function(data) {
      $("#status").html("Sucessfully!!");
      val = val+1;
      $("#loveitBtn").val(val);
      $("#loveitBtn").attr("disabled", "disabled");
      $("#loveitBtn").css("background-image","url(../survey/like.png)");
    });
  }); 
}

Can you please help me to adjust this little code? Am not an expert, I am just starting out learning and I will appreciate any advice. Many thanks Cheers!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are not passing 'loveit' as a parameter in the data:

$.post("../survey/index.php", {op: "notgood"},function(data)...

Should look like:

$.post("../survey/index.php", {op: "notgood", loveit: "true" },function(data)...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda